package com.sina.finance.api.framework.dao.impl;

import com.sina.finance.api.framework.dao.BasicDao;
import com.sina.finance.api.framework.dao.IDemoAPIDao;
import com.sina.finance.api.framework.dao.rowMapper.DemoOrderRowMapper;
import com.sina.finance.api.framework.dao.rowMapper.DemoShipItemRowMapper;
import com.sina.finance.api.framework.dao.rowMapper.DemoShipRowMapper;
import com.sina.finance.api.framework.domain.DemoShipItem;
import com.sina.finance.api.framework.domain.DemoOrder;
import com.sina.finance.api.framework.domain.DemoShip;

import java.util.List;

public class DemoAPIDaoImpl extends BasicDao implements IDemoAPIDao {

	@Override
	public List<DemoShipItem> getShipItemsByShipGUID(String shipGUID) {
		String sql = " SELECT ItemNumber FROM SHIP_ITEM WHERE SHIPGUID = ? ";
		Object[] args = {shipGUID};
		return super.query(sql, args, new DemoShipItemRowMapper());
	}

	@Override
	public DemoOrder getOrderByOrderGUID(String orderGUID) {
		String sql = " SELECT * FROM ROP_Order WHERE OrderGUID = ? ";
		Object[] args = {orderGUID};
		return (DemoOrder)super.queryForObject(sql, args, new DemoOrderRowMapper());
	}

	@Override
	public List<DemoShip> getShips() {
		String sql = " SELECT * FROM SHIP ";
		return super.query(sql, new DemoShipRowMapper());
	}

	@Override
	public int getShipCount() {
		String sql = " SELECT COUNT(1) FROM SHIP ";
		return super.queryForInt(sql);
	}

}
